package fr.afcepf.ticketing.service;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import fr.afcepf.ticketing.dao.CustomerDao;
import fr.afcepf.ticketing.domain.Address;
import fr.afcepf.ticketing.domain.Customer;

@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
@Stateless
public class CustomerServiceBean implements CustomerService {

	@EJB
	private CustomerDao customerDao;

	public Customer authenticateCustomer(String login, String password) {
		return customerDao.authenticateCustomer(login, password);
	}

	public Customer createCustomer(Customer customer, Address address) {
		customer.setAddress(address);
		return customerDao.createCustomer(customer);
	}

	public Customer findCustomer(Long customerId) {
		return customerDao.findCustomer(customerId);
	}

	public List<Customer> findAllCustomers() {
		return customerDao.findAllCustomers();
	}

	public Customer updateCustomer(Customer customer, Address address) {
		customer.setAddress(address);
		return customerDao.updateCustomer(customer);
	}

	public void deleteCustomer(Customer customer) {
		customerDao.deleteCustomer(customer);
	}

	@Override
	public Customer getCustomerByLogin(String login) {
		return customerDao.getCustomerByLogin(login);
	}

	@Override
	public void updateCustomerByLogin(String login, Long id, Customer cust) {
		customerDao.updateCustomerByLogin(login, id, cust);
	}

	@Override
	public Customer merge(Customer cust) {
		customerDao.updateCustomer(cust);
		return cust;
	}

}
